const Joi = require('joi');

//定义对象的验证规则
const schema = {
    username: Joi.string().min(2).max(20).error(new Error('username属性没有通过验证')),
    password: Joi.string().min(6).max(20),
};

// const validation = schema.validate(req.body);
// res.send(validation);


async function run() {
    try {
        //实施验证
        await Joi.validate({ username: 'aa',password: '123123' }, schema);
    }catch(ex) {
        console.log(ex.message);
        return;
    }
    console.log('验证通过');
}

run();